package com.hspedu.list_;

import java.util.Iterator;
import java.util.LinkedList;

@SuppressWarnings({"all"})
public class LinkedListCRUD {
    public static void main(String[] args) {
        LinkedList linkedList = new LinkedList();
        // 添加
        linkedList.add(1);
        linkedList.add(2);
        linkedList.add(3);

        System.out.println("linkedList=" + linkedList);

        // 删除
        Object remove = linkedList.remove();// 删除第一个节点并返回该节点

        System.out.println("linkedList=" + linkedList);
        System.out.println(remove);

        // 修改
        linkedList.set(1, 999);
        System.out.println("linkedList=" + linkedList);

        // 得到某个节点对象
        Object o = linkedList.get(1);
        System.out.println(o);

        // 遍历
        System.out.println("====迭代器====");
        Iterator iterator = linkedList.iterator();// 迭代器
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println(next);
        }
        System.out.println("====增强for====");
        for (Object o1 : linkedList) {// 增强for循环
            System.out.println(o1);
        }
        System.out.println("====for====");
        for (int i = 0; i < linkedList.size(); i++) {
            System.out.println(linkedList.get(i));
        }
    }
}
